package com.lyz.jingjie;

/**
 * @ClassName GenericityTest
 * @Description 泛型方法
 * @Author 2214361854
 * @Date 2022/2/21 17:10
 * @Version 1.0
 */
public class GenericityTest2 {
    public static void main(String[] args) {
        String[] names = {"小王","小亮","小星"};
        printArray(names);

        String[] names2 = null;
        printArray(names2);

        Integer[] arr = {1,2,3};
        printArray(arr);
    }
    public static <T> void printArray(T[] arr){
        if(arr != null){
            StringBuilder sb = new StringBuilder("[");
            for (int i = 0; i < arr.length; i++) {
                sb.append(arr[i]).append(i == arr.length-1?"":",");
            }
            sb.append("]");
            System.out.println(sb);
        }else {
            System.out.println(arr);
        }
    }
}
